import React from "react";
import './index.module.scss';
import { withRouter } from 'react-router-dom';
// import store2 from './../Common/store';


class Login extends React.Component {

    constructor(props) {
        super(props);
        console.log("参数");
        console.log(props);
        console.log(js);
    }

    render() {
        const _this = this;

        const { Button, Checkbox, Form, Input, Divider,message } = antd;
        const { LockOutlined, UserOutlined } = antd.icons;

        const onFinish = (values) => {
            console.log('Received values of form: ', values);

            store.$http.post('/autoApi/IotLogin', values)
                .then(function (res) {
                    console.log(res);
                    if (res.code == 200) {
                        store.saveLoacl("user-title", res.data["user-title"]);
                        store.saveLoacl("user-type", res.data["user-type"]);
                        store.saveLoacl("user-name", res.data["user-name"]);
                        store.saveLoacl("user-role", res.data["user-role"]);
                        store.saveLoacl("access-token", res.data["access-token"]);
                        store.saveLoacl("user-menu-api", res.data["user-menu-api"]);
                        _this.props.history.push("/");
                    } else {
                        console.log("登录失败!");
                        message.error("登录失败，请检查账号和密码!")
                    }
                })
                .catch(function (error) {
                    console.log(error);
                });

        };


        return (<div id="components-demo-normal-login" style={{
            backgroundColor: '#f0f0ff',
            width: '100%',
            height: '100vh',
            margin: '0',
            padding: '0',
            backgroundSize: 'cover',
            backgroundImage: `url(${require('./bg.jpg').default})`
        }}>


            <div id="components-form-demo-normal-login" style={{
                position: 'absolute',
                right: '50px',
                top: 'calc(50% - 120px)',
                width: '300px',
                height: '240px',
                backgroundColor: '#fff',
                boxShadow: '0px 0px 10px #c0c0c0',
                padding: '0px 20px 20px 20px',
                borderRadius: '5px'
            }}>
                <Form
                    name="normal_login"
                    className="login-form"
                    initialValues={{
                        remember: true,
                    }}
                    onFinish={onFinish}
                >
                    <Divider orientation="left">AIot物联网系统</Divider>
                    <Form.Item
                        name="username"
                        rules={[
                            {
                                required: true,
                                message: '请输入账号/手机号!',
                            },
                        ]}
                    >
                        <Input prefix={<UserOutlined className="site-form-item-icon" />} placeholder="账号" />
                    </Form.Item>
                    <Form.Item
                        name="password"
                        rules={[
                            {
                                required: true,
                                message: '请输入密码!',
                            },
                        ]}
                    >
                        <Input
                            prefix={<LockOutlined className="site-form-item-icon" />}
                            type="password"
                            placeholder="密码"
                        />
                    </Form.Item>

                    <Form.Item>
                        <Button type="primary" htmlType="submit" className="login-form-button">
                            确定
                        </Button>
                        &nbsp;或者&nbsp;<a href="">注册账号!</a>
                    </Form.Item>
                </Form>
            </div>

        </div>
        )
    }
}
export default withRouter(Login);